package com.wzh.controll;

import com.wzh.dao.CardDao;
import com.wzh.pojo.Po.*;
import com.wzh.pojo.Req.DataReq;
import com.wzh.pojo.Resp.DataResp;
import com.wzh.pojo.result;
import com.wzh.service.Userser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/User")
public class UserController {
	@Autowired
	private Userser userser;


	//查看所有用户
	@PostMapping("/delUser")
	@ResponseBody
	public DataResp delUser(@RequestBody DataReq req){
		DataResp<Object> resp= userser.delUser(req);
		return resp;
	};

   //查看所有用户
	@PostMapping("/show")
	@ResponseBody
	public DataResp show(@RequestBody DataReq req){
		DataResp<Object> resp= userser.show(req);
		return resp;
	};

	@PostMapping("/login")
	@ResponseBody
	public result login(@RequestBody User user2) {
		User user = userser.login(user2);
		String mes=user!=null?"登陆成功":"账号不存在或者密码错误";
		Integer code=user!=null?200:300;
		return new result(mes,code,user);
	}

	@PostMapping("/register")
	@ResponseBody
	public result register(@RequestBody User user) {
		boolean res = userser.register(user);
		String mes=res!=false?"注册成功":"注册失败";
		Integer code=res!=false?200:300;
		return new result(mes,code);
	}


	//绑定手机设备
	@PostMapping("/boundDev")
	@ResponseBody
	public result boundDev(@RequestBody User user) {
		boolean res = userser.boundDev(user);
		String mes=res!=false?"操作成功":"操作失败";
		Integer code=res!=false?200:300;
		return new result(mes,code);
	}

	//解除绑定手机设备
	@PostMapping("/DelDev")
	@ResponseBody
	public result DelDev(@RequestBody User user) {
		boolean res = userser.DelDev(user);
		String mes=res!=false?"操作成功":"操作失败";
		Integer code=res!=false?200:300;
		return new result(mes,code);
	}

	//读取小程序列表
	@PostMapping("/readList")
	@ResponseBody
	public result readList() {

		List<NameList> list = userser.readNameList();
		String mes=list!=null?"查询成功":"查询失败";
		Integer code=list!=null?200:300;
		return new result(mes,code,list);
	}

	//修改用户vip和余额
	@PostMapping("/UpdateUser")
	@ResponseBody
	public result UpdateUser(@RequestBody User user) {
		boolean res = userser.UPdateVipTime(user);
		String mes=res!=false?"操作成功":"操作失败";
		Integer code=res!=false?200:300;
		return new result(mes,code);
	}

}
